package com.brspace.qualitycontrol.controller.admin;/**
 * @Author wangt
 * @Date 2021/4/20 15:59
 * @Version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.brspace.qualitycontrol.entity.UserRoleRelation;
import com.brspace.qualitycontrol.entity.vo.UserRoleVo;
import com.brspace.qualitycontrol.service.RoleService;
import com.brspace.qualitycontrol.service.UserRoleRelationService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户与角色
 * @Author: Mr.Wang
 * @Date: 2021-04-20 15:59
 **/
@Api(description = "用户与角色")
@RestController
@RequestMapping("/admin/userRole")
public class UserAndRoleController {
    @Resource
    private UserRoleRelationService userRoleRelationService;
    @Resource
    private RoleService roleService;
    /**
     * 获取角色列表
     * @Author: wangt
     * @Date: 2021-04-20 16:05:24
     */
    @ApiOperation("获取角色列表")
    @GetMapping("list")
    public R list(){
        return R.ok().data("list",roleService.list());
    }
    /**
     * 获取分分配用户的角色
     * @Author: wangt
     * @Date: 2021-04-20 16:17:36
     */
    @ApiOperation("获取当前需分配角色的用户的角色")
    @GetMapping("userList/{uid}")
    public R userList(@ApiParam(value = "用户ID" , required = true) @PathVariable String uid){
        return R.ok().data("list",userRoleRelationService.list(new QueryWrapper<UserRoleRelation>().eq("user_id",uid)));
    }
    /**
     * 给用户分配角色
     * @Author: wangt
     * @Date: 2021-04-21 15:06:50
     */
    @ApiOperation("给用户分配角色")
    @PostMapping("add")
    public R add(@RequestBody  UserRoleVo userRoleVo){
        userRoleRelationService.add(userRoleVo);
        return R.ok();
    }
}
